\documentclass[a4paper,12pt]{article}

\usepackage[margin=1.5cm]{geometry}
\usepackage{enumitem}
\usepackage{listings}

\setlength{\parskip}{1.5ex}
\setlength{\parindent}{0pt}

\title{Miscellaneous Useful Things}
\author{Chen Rushan\\chenrsster@gmail.com}
\date{2009.08.09 21:55}

\lstset{
    basicstyle=\ttfamily, columns=flexible, framesep=0pt, framextopmargin=3pt,
    framexbottommargin=3pt, framexleftmargin=-1pt, frame=single,
    aboveskip=0.5cm, belowskip=0.2cm
}

\begin{document}

\section{Getting image properties}

    To get the width and height of an image, use command:

    \begin{lstlisting}[gobble=3]
    identify -format '%w %h\n' image.jpg
    \end{lstlisting}

\section{UUID}

    UUID is so helpful especially when you deal with mobile device. For
    example:\\ You have two mobile device, A and B, and both of them have only
    one partition, and you always want A to be mounted to \verb=/media/A=, B to
    \verb=/media/B=, 

\section{sopcast}

    A simple example of sp-sc command line:

    \begin{lstlisting}[gobble=3]
    sp-sc sop://broker.sopcast.com:3912/6098 3908 8908 > /dev/null &
    \end{lstlisting}

    Start to transfer channel 6098, and you can play it on 8908 with VLC or
    mplayer by open the url: http://localhost:8908/tv.asf

\section{mplayer}

    How do I expand the "area" so that the subtitles are lower on the screen/
    put the subs in the black bars?

    \begin{lstlisting}[gobble=3]
    mplayer -vf expand=:-100::2 
    \end{lstlisting}

\section{Clipboard under X server}

    X defines a thing called {\em selections} which are just clipboards in
    essence, and there're three types of selections:

    \begin{enumerate}[topsep=0pt, itemsep=0pt]
        \item PRIMARY
        \item SECONDARY
        \item CLIPBOARD
    \end{enumerate}

    Actually, no one ever does anything interesting with SECONDARY, so
    generally, only {\em PRIMARY} and {\em CLIPBOARD} selections are used.

    \begin{enumerate}[topsep=0pt, itemsep=0pt]
        \item PRIMARY is used for mouse selection, middle mouse button pastes,
            the selection stays with the application from which it was selected
            (close the app and the selection goes away). (It's also possible to
            paste by pressing SHIFT-INSERT, as in urxvt)

        \item CLIPBOARD is used for Windows-style
            cut(Ctrl-X)/copy(Ctrl-C)/paste(Ctrl-V), which has a separate
            storage location that's application-independent.
    \end{enumerate}

    {\em PRIMARY} and {\em CLIPBOARD} each has different storage, and doesn't
    interfere with each other.

    Here I introduce a tool called {\em xclip} that is used to manipulate those
    selections, by default, it affects the PRIMARY selection. Now let's go
    through some examples:

    To copy the output of a command, say {\em ls}, run:

    \begin{lstlisting}[gobble=3]
    ls | xclip
    \end{lstlisting}

    Now you can use middle mouse button to paste {\em ls} output to X apps.

    To copy a whole file, simply run:

    \begin{lstlisting}[gobble=3]
    xclip file
    \end{lstlisting}

    To paste output, run:

    \begin{lstlisting}[gobble=3]
    xclip -o
    \end{lstlisting}

    As mentioned previously, all the above commands operate on PRIMARY
    selection, and to use the CLIPBOARD selection, which enables the
    Windows-style copy/paste, just add an option as:

    \begin{lstlisting}[gobble=3]
    xclip -selection c
    \end{lstlisting}

    (To explicitly choose the PRIMARY selection, use {\em -selection o})
    
\section{Manipulating PKGBUILD to downgrade/upgrade package}

    Sometimes you find that there's already a newer version package out there,
    but the repository mirror is still not updated, or sometimes you want to
    just downgrade some package. 
    
    One way the achieve the above effect is to modify PKGBUILD, just take the
    following steps:

    \begin{enumerate}
        \item Download PKGBUILD for that package.

        \item Open PKGBUILD with your favorite editor, find those lines starting
            with {\em pkgver, source, md5sums}, for example, like:

            \begin{lstlisting}[gobble=11]
            pkgver=20091028
            source=(ftp://ftp.videolan.org/p...ots/x264-snapshot-$pkgver-2245.tar.bz2)
            md5sums=('9362f2cba0c64378cd3ad48f6e91bd74')
            \end{lstlisting}

            From {\em source} line, we know the site where the package currently
            installed in your system resides, and generally that is also where
            older and newer versions of that package reside, so to download a
            different version, you only need to modify {\em source} to make it
            point to the version you want. Generally, the difference between
            various version names only lie in {\em pkgver}, so you just need to
            modify {\em pkgver}.

        \item Then run \verb=makepkg=, it will download the package for you, but
            after the download completes, md5sum checking will fail, that's
            expected, since current md5sum is not for your version. In order to
            make \verb=makepkg= run successfully, you need to get the md5sum of
            your version, and then modify the {\em md5sum} line in PKGBUILD. To
            get md5sum, run:

            \begin{lstlisting}[gobble=11]
            md5sum <your-package>
            \end{lstlisting}

        \item Then wait until \verb=makepkg= finishes, run:

            \begin{lstlisting}[gobble=11]
            pacman -U <package-name>.pkg.tar.gz
            \end{lstlisting}

        \item Now package downgrading or upgrading is DONE.
    
    \end{enumerate}
        
\end{document}

